/*
 * Copyright (c) 2022, IMMORTA Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * - Neither the name of IMMORTA Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef ADC_DRV_H
#define ADC_DRV_H

/*!
 * @file adc_drv.h
 * @brief This file declares adc driver interfaces
 */

/*!
 * @addtogroup adc_drv
 * @{
 */

/*******Includes***************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "stdio.h"
#include "errcodes.h"
#include "device_registers.h"
#include "clock_drv.h"

/*******Definitions************************************************************/

/*!
 * @brief ADC interrupt status structure
 */
typedef struct {
    uint8_t allEosFlag;     /*!< All channel end of sequence conversion flag */
    uint32_t allNeocFlag;   /*!< All end of normal channel conversion flag */
    uint8_t allPeocFlag;    /*!< All end of priortiy channel conversion flag */
    uint32_t allNawdFlag;   /*!< All normal channel analog watchdog flag */
    uint8_t allPawdFlag;    /*!< All priortiy channel analog watchdog flag */
} adc_int_state_t;

/*! @brief ADC Callback function define */
typedef void (*adc_callback_t)(uint32_t instance, void* param);

/*!
 * @brief ADC input channel enumeration
 */
typedef enum {
    ADC_EXTERNAL_CHANNEL0 = 0U,        /*!< ADC external channel0 */
    ADC_EXTERNAL_CHANNEL1 = 1U,           /*!< ADC external channel1 */
    ADC_EXTERNAL_CHANNEL2 = 2U,           /*!< ADC external channel2 */
    ADC_EXTERNAL_CHANNEL3 = 3U,           /*!< ADC external channel3 */
    ADC_EXTERNAL_CHANNEL4 = 4U,           /*!< ADC external channel4 */
    ADC_EXTERNAL_CHANNEL5 = 5U,           /*!< ADC external channel5 */
    ADC_EXTERNAL_CHANNEL6 = 6U,           /*!< ADC external channel6 */
    ADC_EXTERNAL_CHANNEL7 = 7U,           /*!< ADC external channel7 */
    ADC_EXTERNAL_CHANNEL8 = 8U,           /*!< ADC external channel8 */
    ADC_EXTERNAL_CHANNEL9 = 9U,           /*!< ADC external channel9 */
    ADC_EXTERNAL_CHANNEL10 = 10U,         /*!< ADC external channel10 */
    ADC_EXTERNAL_CHANNEL11 = 11U,         /*!< ADC external channel11 */
    ADC_EXTERNAL_CHANNEL12 = 12U,         /*!< ADC external channel12 */
    ADC_EXTERNAL_CHANNEL13 = 13U,         /*!< ADC external channel13 */
    ADC_EXTERNAL_CHANNEL14 = 14U,         /*!< ADC external channel14 */
    ADC_EXTERNAL_CHANNEL15 = 15U,         /*!< ADC external channel15 */
    ADC_EXTERNAL_CHANNEL16 = 16U,         /*!< ADC external channel16 */
    ADC_EXTERNAL_CHANNEL17 = 17U,         /*!< ADC external channel17 */
    ADC_EXTERNAL_CHANNEL18 = 18U,         /*!< ADC external channel18 */
    ADC_EXTERNAL_CHANNEL19 = 19U,         /*!< ADC external channel19 */
    ADC_INTERNAL_BANDGAP_TSENSOR = 32,    /*!< ADC inernal channel bandgap or tsensor */
    ADC_INTERNAL_VDDA = 33U,              /*!< ADC inernal channel vdda */
    ADC_INTERNAL_VREFH = 34U,             /*!< ADC inernal channel vrefh */
    ADC_INTERNAL_DAC_OUT = 35U,           /*!< ADC inernal channel dac out */
    ADC_INTERNAL_DIGLDO = 36U,            /*!< ADC inernal channel DIGLDO */
    ADC_INTERNAL_FLHLDO = 37U             /*!< ADC inernal channel FLHLDO */
} adc_input_channel_t;

/*!
 * @brief ADC normal channel enumeration
 */
typedef enum {
    ADC_NORMAL_CHANNEL0 = 0U,        /*!< ADC normal channel0 */
    ADC_NORMAL_CHANNEL1,             /*!< ADC normal channel1 */
    ADC_NORMAL_CHANNEL2,             /*!< ADC normal channel2 */
    ADC_NORMAL_CHANNEL3,             /*!< ADC normal channel3 */
    ADC_NORMAL_CHANNEL4,             /*!< ADC normal channel4 */
    ADC_NORMAL_CHANNEL5,             /*!< ADC normal channel5 */
    ADC_NORMAL_CHANNEL6,             /*!< ADC normal channel6 */
    ADC_NORMAL_CHANNEL7,             /*!< ADC normal channel7 */
    ADC_NORMAL_CHANNEL8,             /*!< ADC normal channel8 */
    ADC_NORMAL_CHANNEL9,             /*!< ADC normal channel9 */
    ADC_NORMAL_CHANNEL10,            /*!< ADC normal channel10 */
    ADC_NORMAL_CHANNEL11,            /*!< ADC normal channel11 */
    ADC_NORMAL_CHANNEL12,            /*!< ADC normal channel12 */
    ADC_NORMAL_CHANNEL13,            /*!< ADC normal channel13 */
    ADC_NORMAL_CHANNEL14,            /*!< ADC normal channel14 */
    ADC_NORMAL_CHANNEL15,            /*!< ADC normal channel15 */
    ADC_NORMAL_CHANNEL16,            /*!< ADC normal channel16 */
    ADC_NORMAL_CHANNEL17,            /*!< ADC normal channel17 */
    ADC_NORMAL_CHANNEL18,            /*!< ADC normal channel18 */
    ADC_NORMAL_CHANNEL19,            /*!< ADC normal channel19 */
} adc_normal_channel_t;

/*!
 * @brief ADC priority channel enumeration
 */
typedef enum {
    ADC_PRIORITY_CHANNEL0 = 0U,        /*!< ADC priority channel0 */
    ADC_PRIORITY_CHANNEL1 = 1U,        /*!< ADC priority channel1 */
    ADC_PRIORITY_CHANNEL2 = 2U,        /*!< ADC priority channel2 */
    ADC_PRIORITY_CHANNEL3 = 3U         /*!< ADC priority channel3 */
} adc_priority_channel_t;

/*!
 * @brief ADC analog watchdog enumeration
 */
typedef enum {
    ADC_ANALOG_WATCHDOG0 = 0U,    /*!< ADC analog watchdog0 */
    ADC_ANALOG_WATCHDOG1 = 1U,    /*!< ADC analog watchdog1 */
    ADC_ANALOG_WATCHDOG2 = 2U,    /*!< ADC analog watchdog2 */
    ADC_ANALOG_WATCHDOG3 = 3U     /*!< ADC analog watchdog3 */
} adc_analog_watchdog_t;

/*!
 * @brief ADC trigger type enumeration
 */
typedef enum {
    ADC_SOFTWARE_TRIGGER = 0U,   /*!< Software trigger */
    ADC_HARDWARE_TRIGGER = 1U    /*!< Hardware trigger */
} adc_trigger_type_t;

/*!
 * @brief ADC dma mode enumeration
 */
typedef enum {
    ADC_DMA_DISABLE = 0U,                   /*!< Dma disable */
    ADC_NORMAL_CHANNEL_DMA_ENABLE = 1U,     /*!< Dma enable for normal channel */
    ADC_PRIORITY_CHANNEL_DMA_ENABLE = 2U    /*!< Dma enable for priority channel */
} adc_dma_mode_t;

/*!
 * @brief ADC conversion mode enumeration
 */
typedef enum {
    ADC_SINGLE_MODE = 0U,       /*!< Single mode */
    ADC_SCAN_MODE = 1U,         /*!< Scan mode */
    ADC_CONTINOUS_MODE = 2U     /*!< Continous mode */
} adc_conversion_mode_t;

/*!
 * @brief ADC conversion resolution enumeration
 */
typedef enum {
    ADC_RESOLUTION_12BIT = 0U,       /*!< 12-bit resolution mode */
    ADC_RESOLUTION_10BIT = 1U,       /*!< 10-bit resolution mode */
    ADC_RESOLUTION_8BIT = 2U         /*!< 8-bit resolution mode */
} adc_resolution_t;

/*!
 * @brief ADC hardware average enumeration
 */
typedef enum {
    ADC_AVERAGE_4 = 0U,         /*!< Hardware average of 4 samples */
    ADC_AVERAGE_8 = 1U,         /*!< Hardware average of 8 samples */
    ADC_AVERAGE_16 = 2U,        /*!< Hardware average of 16 samples */
    ADC_AVERAGE_32 = 3U         /*!< Hardware average of 32 samples */
} adc_average_t;

/*!
 * @brief ADC positive reference voltage enumeration
 */
typedef enum {
    ADC_VDDA = 0U,              /*!< Select vdda as positive reference voltage */
    ADC_EXTERNAL_VREFH = 1U,    /*!< Select external vrefh as positive reference voltage */
} adc_vrefp_t;

#if (CONFIG_ADC_SUPPORT_VREFL == 1U)
/*!
 * @brief ADC negative reference voltage enumeration
 */
typedef enum {
    ADC_GND = 0U,               /*!< Select gnd as negative reference voltage */
    ADC_EXTERNAL_VREFL = 1U     /*!< Select external vrefl as negative reference voltage */
} adc_vrefn_t;
#endif

/*!
 * @brief ADC sample time enumeration
 */
typedef enum {
    ADC_SAMPLE_5_CYCLES = 0U,               /*!< Sample time is 5 cycles */
    ADC_SAMPLE_9_CYCLES = 1U,               /*!< Sample time is 9 cycles */
    ADC_SAMPLE_10_CYCLES = 2U,              /*!< Sample time is 10 cycles */
    ADC_SAMPLE_30_CYCLES = 3U,              /*!< Sample time is 30 cycles */
    ADC_SAMPLE_45_CYCLES = 4U,              /*!< Sample time is 45 cycles */
    ADC_SAMPLE_60_CYCLES = 5U,              /*!< Sample time is 60 cycles */
    ADC_SAMPLE_80_CYCLES = 6U,              /*!< Sample time is 80 cycles */
    ADC_SAMPLE_240_CYCLES = 7U              /*!< Sample time is 240 cycles */
} adc_sample_time_t;

/*!
 * @brief ADC buffer select enumeration
 */
typedef enum {
    ADC_BUFFER_DISABLE = 0U,               /*!< Buffer disable */
    ADC_BUFFER_BANDGAP = 1U,               /*!< Buffer select bandgap */
    ADC_BUFFER_TSENSOR = 2U                /*!< Buffer select tsensor */
} adc_buffer_sel_t;

/*!
 * @brief ADC normal channel config structure
 */
typedef struct {
    adc_input_channel_t channel;        /*!< ADC input channel */
    adc_sample_time_t sampleTime;       /*!< ADC sample time */
    bool neocIntEn;                     /*!< ADC end of normal channel conversion interrupt enable */
    bool awdIntEn;                      /*!< ADC channel analog watchdog interrupt enable */
    bool awdTrigEn;                     /*!< ADC channel analog watchdog trigger icm enable */
    bool awdEn;                         /*!< ADC channel analog watchdog enable */
    adc_analog_watchdog_t awdSel;       /*!< ADC channel analog watchdog select */
} adc_normal_ch_config_t;

/*!
 * @brief ADC priority channel config structure
 */
typedef struct {
    adc_input_channel_t channel;        /*!< ADC input channel */
    adc_sample_time_t sampleTime;       /*!< ADC sample time */
    uint16_t offset;                    /*!< ADC priority channel offset value */
    bool peocIntEn;                     /*!< ADC end of priority channel conversion interrupt enable */
    bool awdIntEn;                      /*!< ADC channel analog watchdog interrupt enable */
    bool awdTrigEn;                     /*!< ADC channel analog watchdog trigger icm enable */
    bool awdEn;                         /*!< ADC channel analog watchdog enable */
    adc_analog_watchdog_t awdSel;       /*!< ADC channel analog watchdog select */
} adc_priority_ch_config_t;

/*!
 * @brief ADC normal channel sequence config structure
 */
typedef struct {
    adc_trigger_type_t triggerType;         /*!< ADC conversion trigger type */
    adc_conversion_mode_t mode;             /*!< ADC normal channel sequence work mode */
    bool neosIntEn;                         /*!< ADC end of normal channel sequence conversion interrupt enable */
    uint8_t sequenceLen;                    /*!< ADC normal channel sequence length,
                                                 0 indicates that the actual sequence length is 1 */
    adc_normal_ch_config_t* chConfig;       /*!< ADC normal channel config */
} adc_normal_sequence_config_t;

/*!
 * @brief ADC priority channel sequence config structure
 */
typedef struct {
    adc_trigger_type_t triggerType;        /*!< ADC conversion trigger type */
    adc_conversion_mode_t mode;            /*!< ADC priority channel sequence work mode */
    bool peosIntEn;                        /*!< ADC end of priority channel sequence conversion interrupt enable */
    uint8_t sequenceLen;                   /*!< ADC priority channel sequence length,
                                                0 indicates that the actual sequence length is 1 */
    adc_priority_ch_config_t* chConfig;    /*!< ADC priority channel config */
} adc_priority_sequence_config_t;

/*!
 * @brief ADC analog watchdog channel config structure
 */
typedef struct {
    adc_analog_watchdog_t awdChannel;    /*!< Analog watchdog channel */
    uint16_t awdLowThreshold;            /*!< Analog watchdog low threshold */
    uint16_t awdHighThreshold;           /*!< Analog watchdog high threshold */
} adc_analog_watchdog_ch_config_t;

/*!
 * @brief ADC analog watchdog config structure
 */
typedef struct {
    uint8_t awdNum;                                 /*!< Analog watchdog channel num */
    adc_analog_watchdog_ch_config_t* awdChConfig;   /*!< Analog watchdog channel config */
} adc_analog_watchdog_config_t;

/*!
 * @brief ADC conversion config structure
 */
typedef struct {
    adc_clk_src_t srcClk;                                 /*!< Source clock select */
    bool adcEn;                                           /*!< Enable/Disable ADC */
    bool intEn;                                           /*!< Enable/Disable ADC interrupt */
    adc_resolution_t resolution;                          /*!< Sample resolution */
    adc_average_t averageTimes;                           /*!< Average times */
    bool averageEn;                                       /*!< Enable/disable average */
    adc_dma_mode_t dmaMode;                               /*!< ADC dma work mode */
    adc_vrefp_t vrefpSel;                                 /*!< ADC positive reference voltage select */
#if (CONFIG_ADC_SUPPORT_VREFL == 1U)
    adc_vrefn_t vrefnSel;                                 /*!< ADC negative reference voltage select */
#endif
    adc_normal_sequence_config_t* normalSequence;         /*!< Normal channel sequence config */
    adc_priority_sequence_config_t* prioritySequence;     /*!< Priority channel sequence config */
    adc_buffer_sel_t bufferSel;                           /*!< ADC Buffer select for bandgap or tensor */
    adc_callback_t callback;                              /*!< Interrupt callback pointer */
} adc_conversion_config_t;

/*******APIs*******************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif

/*!
 * @brief Configure ADC normal channel and priority channel conversion function
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] config: Configuration of the ADC conversion function
 * @return None
 */
void ADC_Init(uint32_t instance, adc_conversion_config_t* config);

/*!
 * @brief Get ADC default configuration about conversion function
 *
 * @param[in] None
 * @param[out] config: Configuration of the ADC conversion function
 * @return None
 */
void ADC_GetDefaultConfig(adc_conversion_config_t* config);

/*!
 * @brief Configure ADC normal channel sequence conversion related functions
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] config: Configuration of the ADC normal channel sequence conversion function
 * @return None
 */
void ADC_InitNormalSequence(uint32_t instance, const adc_normal_sequence_config_t* config);

/*!
 * @brief Configure ADC normal channel conversion related functions
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] channel: Normal channel number
 * @param[in] config: Configuration of the ADC normal channel conversion function
 * @return None
 */
void ADC_InitNormalChannel(uint32_t instance, adc_normal_channel_t channel,
                           const adc_normal_ch_config_t* config);

/*!
 * @brief Configure ADC normal channel sequence length
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] len: Normal channel sequence length
 * @return None
 */
void ADC_SetNormalChSequenceLen(uint32_t instance, uint8_t len);

/*!
 * @brief Configure ADC priority channel sequence conversion related functions
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] config: Configuration of the ADC priority channel sequence conversion function
 * @return None
 */
void ADC_InitPrioritySequence(uint32_t instance, const adc_priority_sequence_config_t* config);

/*!
 * @brief Configure ADC priority channel conversion related functions
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] channel: Priority channel number
 * @param[in] config: Configuration of the ADC priority channel conversion function
 * @return None
 */
void ADC_InitPriorityChannel(uint32_t instance, adc_priority_channel_t channel,
                             const adc_priority_ch_config_t* config);

/*!
 * @brief Configure ADC priority channel sequence length
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] len: Priority channel sequence length
 * @return None
 */
void ADC_SetPriorityChSequenceLen(uint32_t instance, uint8_t len);

/*!
 * @brief Configure ADC analog watchdog function
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] config: Configuration of the ADC analog watchdog
 * @return None
 */
void ADC_InitAnalogWatchdog(uint32_t instance, const  adc_analog_watchdog_config_t* config);

/*!
 * @brief Configure ADC analog watchdog high threshold
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] awdCh: Analog watchdog channel
 * @param[in] threshold: Analog watchdog high threshold
 * @return None
 */
void ADC_SetAwdHighThreshold(uint32_t instance, adc_analog_watchdog_t awdCh, uint16_t threshold);

/*!
 * @brief Configure ADC analog watchdog low threshold
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] awdCh: Analog watchdog channel
 * @param[in] threshold: Analog watchdog low threshold
 * @return None
 */
void ADC_SetAwdLowThreshold(uint32_t instance, adc_analog_watchdog_t awdCh, uint16_t threshold);

/*!
 * @brief Set ADC sample resolution
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] resolution
 *            - 0: ADC_RESOLUTION_12BIT
 *            - 1: ADC_RESOLUTION_10BIT
 *            - 2: ADC_RESOLUTION_8BIT
 * @return None
 */
void ADC_SetDataResolution(uint32_t instance, adc_resolution_t resolution);

/*!
 * @brief Set ADC sample avergae function
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] averageTimes
 *            - 0: ADC_AVERAGE_4
 *            - 1: ADC_AVERAGE_8
 *            - 2: ADC_AVERAGE_16
 *            - 3: ADC_AVERAGE_32
 * @param[in] averageEn
 *            - true: Enable average function
 *            - false: Disable average function
 * @return None
 */
void ADC_SetSampleAverage(uint32_t instance, adc_average_t averageTimes, bool averageEn);

/*!
 * @brief ADC buffer select for bandgap or tensor
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] adc_buffer_sel_t
 *            - ADC_BUFFER_DISABLE: Buffer disable
 *            - ADC_BUFFER_BANDGAP: Buffer select bandgap
 *            - ADC_BUFFER_TSENSOR: Buffer select tsensor
 * @return None
 */
void ADC_SetBufferSel(uint32_t instance, adc_buffer_sel_t bufferSel);

/*!
 * @brief Get ADC normal channel conversion result
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[out] channel: Normal channel number
 * @return The conversion result of normal channel
 */
uint16_t ADC_GetNormalChResult(uint32_t instance, adc_normal_channel_t channel);

/*!
 * @brief Get ADC priority group conversion result
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[out] channel: Priority channel number
 * @return The conversion result of priority channel
 */
int16_t ADC_GetPriorityChResult(uint32_t instance, adc_priority_channel_t channel);

/*!
 * @brief Enable/Disable ADC calibration function
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] calibrationEn
 *            - true: Enable calibration function
 *            - false: Disable calibration function
 * @return None
 */
void ADC_SetCalibrationEn(uint32_t instance, bool calibrationEn);

/*!
 * @brief Stop ADC current conversion
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return None
 */
void ADC_StopConversion(uint32_t instance);

/*!
 * @brief Set software trigger for normal channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return None
 */
void ADC_SetNormalChSoftwareTrigger(uint32_t instance);

/*!
 * @brief Set software trigger for priority channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return None
 */
void ADC_SetPriorityChSoftwareTrigger(uint32_t instance);

/*!
 * @brief Get ADC idle status
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return Idle status
 */
bool ADC_GetIdleStatus(uint32_t instance);

/*!
 * @brief Get calibration offset error
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return Offset error value
 */
uint16_t ADC_GetOffsetError(uint32_t instance);

/*!
 * @brief Get calibration gain error
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return Gain error value
 */
uint16_t ADC_GetGainError(uint32_t instance);

/*!
 * @brief Get tsensor error value
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return Tsensor error value
 */
uint16_t ADC_GetTsensorError(uint32_t instance);

/*!
 * @brief Get All end of sequence conversion flag for normal channel and priority channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return All eos flag
 */
uint8_t ADC_GetAllEOSFlag(uint32_t instance);

/*!
 * @brief Clear All end of sequence conversion flag for normal channel and priority channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] eosMsk: End of sequence conversion flag mask
 * @return None
 */
void ADC_ClrAllEOSFlag(uint32_t instance, uint8_t eosMsk);

/*!
 * @brief Get all end of channel conversion flag for normal channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return All NEOC flag
 */
uint32_t ADC_GetAllNEOCFlag(uint32_t instance);

/*!
 * @brief Clear all end of channel conversion flag for normal channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] neocMsk: End of channel conversion flag mask
 * @return None
 */
void ADC_ClrAllNEOCFlag(uint32_t instance, uint32_t neocMsk);

/*!
 * @brief Get all end of channel conversion flag for priority channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return All PEOC flag
 */
uint8_t ADC_GetAllPEOCFlag(uint32_t instance);

/*!
 * @brief Clear all end of channel conversion flag for priority channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] peocMsk: End of channel conversion flag mask
 * @return None
 */
void ADC_ClrAllPEOCFlag(uint32_t instance, uint8_t peocMsk);

/*!
 * @brief Get all analog watchdog event flag for normal channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return Analog watchdog event flag
 */
uint32_t ADC_GetAllNAwdFlag(uint32_t instance);

/*!
 * @brief Clear all analog watchdog event flag for normal channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] nawdMsk: Analog watchdog event flag mask
 * @return None
 */
void ADC_ClrAllNAwdFlag(uint32_t instance, uint32_t nawdMsk);

/*!
 * @brief Get all analog watchdog event flag for priority channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return Analog watchdog event flag
 */
uint8_t ADC_GetAllPAwdFlag(uint32_t instance);

/*!
 * @brief Clear all analog watchdog event flag for priority channel
 *
 * @param[in] instance: The ADC peripheral instance number
 * @param[in] pawdMsk: Analog watchdog event flag mask
 * @return None
 */
void ADC_ClrAllPAwdFlag(uint32_t instance, uint8_t pawdMsk);

/*!
 * @brief Deinit ADC
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return None
 */
void ADC_Deinit(uint32_t instance);

/*!
 * @brief ADC interrupt interrupt implement
 *
 * @param[in] instance: The ADC peripheral instance number
 * @return None
 */
void ADC_IRQHandlerProcess(uint32_t instance);

#if defined(__cplusplus)
}
#endif

/*! @} */

#endif /* ADC_DRV_H */

/*******EOF********************************************************************/

